import { _decorator, Component, find, Label } from 'cc';
import { GameUtil } from './GameUtil';
const { ccclass, property } = _decorator;

@ccclass('Money')
export class Money extends Component {
    @property(Label)
    MoneyLabel: Label = null;

    // MoneyLabel: Label = null;
    money: number = 0;

    protected onLoad(): void {
        if (!this.MoneyLabel) {
            this.MoneyLabel = find("Num", this.node).getComponent(Label);
        }
    }

    setMoney(num: number) {
        if (!this.MoneyLabel) {
            console.error("没找到Label！！！", this.node.name, this.node.parent.name);
            return;
        }
        this.money = num;
        this.MoneyLabel.string = GameUtil.formatNumber(this.money);
    }

    addMoney(num: number) {
        if (!this.MoneyLabel) {
            console.error("没找到Label！！！", this.node.name);
            return;
        }
        this.money += num;
        this.MoneyLabel.string = GameUtil.formatNumber(this.money);
    }



}


